package com.ck.photo;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.crypto.SecureUtil;

import java.io.File;
import java.util.Map;
import java.util.Set;

public class ComparePhoto {

    public static void main(String[] args) {
        String source = "E:\\photo\\相机胶卷";
        String dest = "G:\\照片";
        Map<String, File> dirPhoto = getDirPhoto(source);
        Map<String, File> destPhoto = getDirPhoto(dest);
        Set<String> shaSet = destPhoto.keySet();
        Set<Map.Entry<String, File>> entries = dirPhoto.entrySet();
        for(Map.Entry<String, File> entry : entries){
            if(!shaSet.contains(entry.getKey())){
                String name = entry.getValue().getName();
                FileUtil.copy(entry.getValue(),new File(dest+"\\"+name),true);
                System.out.println("copy 文件：" + name);
            }
        }
    }


    private static Map<String, File> getDirPhoto(String dir){
        File[] files = FileUtil.ls(dir);
        Map<String,File> map = MapUtil.newHashMap(files.length);
        for(File f : files){
            map.put(SecureUtil.sha1(f),f);
        }
        return map;
    }
}
